package stark.app.function.callrec;

import android.widget.TextView;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.stark.callrec.lib.CallType;
import com.stark.callrec.lib.db.CallRecBean;

import androidx.annotation.NonNull;
import stark.app.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.utils.TimeUtil;

/**
 * Author：daizhongbin on 2022/10/31
 * Email：1027154338@qq.com
 * Desc:
 */
public class CallRecAdapter extends StkProviderMultiAdapter<CallRecBean> {

    private int selPos = 0;

    public CallRecAdapter() {
        super(1);
        addItemProvider(new ItemProvider());
    }

    public void setSelPos(int selPos) {
        if (this.selPos == selPos) {
            return;
        }
        this.selPos = selPos;
        notifyDataSetChanged();
    }

    private class ItemProvider extends BaseItemProvider<CallRecBean> {

        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_call_rec;
        }

        @Override
        public void convert(@NonNull BaseViewHolder holder, CallRecBean bean) {
            int pos = holder.getAdapterPosition();
            holder.itemView.setSelected(pos == selPos);

            TextView tvCallType = holder.getView(R.id.tvCallType);
            tvCallType.setText(bean.callType == CallType.CALL_IN ? "来电" : "去电");

            holder.setText(R.id.tvName, "联系人：" + bean.name);
            holder.setText(R.id.tvNumber, "号码：" + bean.number);
            holder.setText(R.id.tvCreateTime, "创建时间：" + TimeUtil.getCnYmd(bean.createTime));
            holder.setText(R.id.tvDuration, "时长：" + TimeUtil.getMmss(bean.duration));
        }
    }

}
